package org.sgx.gwtjsutiltest.client.appstate;

import org.sgx.jsutil.client.DOMUtil;
import org.sgx.jsutil.client.appstate.AppState;

import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.UIObject;
/**
 * abstract AppState for this application (Using UIObject views). 
 * @author sg
 *
 */
public abstract class MyAppState implements AppState {
	
	Element containerEl = null;
	UIObject view = null; 

	protected abstract UIObject buildNewView(); 

	String name;

	public MyAppState(Element containerEl, String name) {
		this.containerEl = containerEl;
		this.name = name;
	}
	
	public UIObject getView() {
		if(view==null)
			view = buildNewView(); 
		return view; 		
	}

	@Override
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Element getContainerEl() {
		return containerEl;
	}

	public void setContainerEl(Element containerEl) {
		this.containerEl = containerEl;
	}

	@Override
	public void perform(String params) {
		DOMUtil.clear(getContainerEl()); 
		getContainerEl().appendChild(getView().getElement()); 
	}
	@Override
	public void uninstall() {
		// TODO Auto-generated method stub
		
	}
}
